package com.podcstr.entity;

import com.podcstr.validator.Email;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @author azim
 * @since 5/9/13 
 */


@Entity
@Table(name = "tb_users", uniqueConstraints = @UniqueConstraint(columnNames = {"email", "username"}))
@NamedQueries(value = {
        @NamedQuery(name = "tb_users.findAllUsers", query = "SELECT u FROM User u"),
        @NamedQuery(name = "tb_users.countUsers", query = "SELECT COUNT(u)  FROM User u"),
        @NamedQuery(name = "tb_users.delete", query = "DELETE  FROM User u WHERE u.id =:id"),
        @NamedQuery(name = "tb_users.findByUserName", query = "SELECT u FROM User u WHERE u.username =:username")
})
public class User extends PersistanceObject {

    @NotNull
    @Size(min = 6, max = 20)
    private String username;

    @NotNull
    @Size(min = 6, max = 100)
    private String password;

    @Transient
    private String confirmPassword;

    @NotNull
    @Size(max = 100)
    @Email
    private String email;

    @NotNull
    private boolean active;

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLoginTime;

    @NotNull
    private String activationkey;

    @OneToOne
    private UserProfile userProfile;

    /**
     * Getters and Setters Methods
     *
     * @return
     */

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getActivationkey() {
        return activationkey;
    }

    public void setActivationkey(String activationkey) {
        this.activationkey = activationkey;
    }

    public UserProfile getUserProfile() {
        return userProfile;
    }

    public void setUserProfile(UserProfile userProfile) {
        this.userProfile = userProfile;
    }
}
